﻿/**
*@description 客源表单
*/
Chenxin.UI.CustomerForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: 'service/CustomerMgr.ashx',
    id: 'customerWin',
    renderTo: 'jqm_customer',
    jqmWidth: 600,
	defBBtn:true,
    initFormValidator: function() {
        var _this = this;
        //电话
        $("#txtMobile").formValidator({
            validatorgroup: this.id,
            onshow: "请输入手机或者电话",
            onfocus: "请输入手机或者电话。",
            oncorrect: " ", onerror: "请输入手机或者电话"
        }).functionValidator({
            fun: function(val, elem) {
                if (val == "") return true; return val.isMobile(); }, onerror: "请输入正确的手机号"
        });
		//电话
        $("#txtPhone").formValidator({ 
			validatorgroup: this.id,
            onshow: "请输入电话", onfocus: "请输入电话", oncorrect: " "
        }).functionValidator({
            fun: function(val, elem) {
                if ($("#txtPhone").val() == "" && $("#txtMobile").val() == "") {
                    return false;
                } else {
                    return true;
                }
            }, onerror: "请输入手机号码或电话"
        });
	},
    createForm: function() {
        return Chenxin.FormCommon.customerForm('customer');
    },
    createComboList: function() {
        var certificateType = new Chenxin.UI.ParameterCombo({
            containerId: '#customer_CertificateType',
            name: 'CertificateType',
            key: 'Custom.CertificateType',
            inModelType: 'txt',
            tbxWidth: 95
        });
        var nationality = new Chenxin.UI.Combo({
            containerId: '#customer_Nationality',
            name: 'Nationality',
            inModelType: 'txt',
            tbxWidth: 95,
            items: comboCommon.country
        });
        return [certificateType, nationality];
    },
    showTraceWin: function() {
        var _this = this;
        if (!this.traceWin) {
            this.traceWin = new Chenxin.UI.CustomerTraceForm({
                scrop: _this,
                afterGetFormJson: function(json) {
                    delete json.AddPerson;
                    delete json.AddDepart;
                    json.HouseAddress = json.Address;
                    json.HouseId = _this.currentCustomerInfo.CustomerId;
                    json.HouseCode = _this.currentCustomerInfo.CustomerCode;
                    json.HouseAddress = _this.currentCustomerInfo.CustomerName;
                    json.status = 1;
                    delete json.Address;
                    delete json.CustomerCode;

                    if (this.isNotice) {
                        this.additionalParam.noticemodel = {
                            body: json.body,
                            NoticeTime: json.SendDate,
                            //HouseId: _this.currentId,
                            HouseAddress: _this.currentCustomerInfo.CustomerName
                        };
                        delete json.body;
                        delete json.SendDate;
                    } else {
                        this.additionalParam = {};
                    }
                    this.additionalParam.isnotice = json.isnotice || '0';
                    delete json.isnotice;
                }
            });
        }
        this.traceWin.show();
        $('#tr_noticetime').hide();
        $('#tr_noticecontent').hide();
        var _data = this.currentCustomerInfo;
        _data.HouseCode = this.currentCustomerInfo.CustomerCode;
        _data.AddPerson = this.currentCustomerInfo.OprPerson;
        _data.AddDepart = this.currentCustomerInfo.OprDepart;
        this.traceWin.fitData(_data);
        this.traceWin.setTitle('客源跟单');
    },

    initEvent: function() {
        var _this = this;
        $('#customer_Save').live('click', function() {
            _this.save();
        });
        $('#customer_Cancle').live('click', function() {
            _this.hide();
        });
        $('#customerTrace').live('click', function() {
            _this.hide();
            _this.showTraceWin();
        });

    },
    initComponent: function() {
        Chenxin.UI.CustomerForm.superclass.initComponent.call(this);
    }
});

Chenxin.FormCommon.customerForm=function(comboIdPrefix){
return '<table class="tbl_f"><tbody><tr><th>客户编号：</th><td><input type="hidden"  name="CustomerId" /><input type="text" name="CustomerCode" class="inputbox_n"/><a class="btn_n fl" style="float: right;"  href="#"  id="customerTrace"><span>跟单</span></a></td></tr><tr><th>客户姓名：</th><td><input type="text"  maxlength="25"  name="CustomerName" class="inputbox_n"/></td></tr><tr><th>性别：</th> <td><input type="radio" name="Sex" value="10" />男 <input type="radio" name="Sex" class="" value="20" />女</td></tr><tr><th>证件类型：</th><td><div style="z-index: 909; margin-right: 5px;" id="' + comboIdPrefix + '_CertificateType" class="SelectWrapSingle"></div></td></tr><tr><th>证件号：</th><td> <input name="CertificateNo"  maxlength="25"  class="inputbox_n" type="text" /></td></tr><tr><th>国籍：</th><td><div style="z-index: 908; margin-right: 5px;" id="' + comboIdPrefix + '_Nationality" class="SelectWrapSingle"></div></td></tr><tr><th>联系电话：</th><td><div style="float:left;"><input name="Phone" maxlength="50"  class="inputbox_n" id="txtPhone" type="text" /></div><div style="float:left" id="txtPhoneTip"/></td></tr><tr><th>手机：</th><td><div style="float:left;"><input name="Mobile"  maxlength="11"  class="inputbox_n" id="txtMobile" type="text" /></div><div style="float:left" id="txtMobileTip"/></td></tr><tr><th>地址：</th><td><input type="text" maxlength="50" name="Address" class="inputbox_n" style="width:360px;"/></td></tr></tbody> </table>';
};
//<tr><th></th><td><div style="float:right; margin-right:15px;_margin-right:10px;*+margin-right:19px;"><a class="btn_n fl"  href="#"  id="' + comboIdPrefix + '_Save"><span>提交</span></a><a id="' + comboIdPrefix + '_Cancle" class="btn_n fl"  href="#" ><span>关闭</span></a></div></td></tr>